<template>
	<view>
		<input type="text" placeholder="输入内容" />
		<button type="primary" @click="keyBoard1">隐藏软键盘</button>
		<view style="margin-top: 40rpx;">监听到键盘高度：{{KeyboardHeight}}</view>
		<button style="margin-top: 40rpx;" type="primary" @click="keyBoard2">取消监听</button>
		<view style="margin-top: 40rpx;">在input、textarea等focus之后，获取输入框的光标位置。</view>
		<uni-easyinput @focus="focus"></uni-easyinput>
		<view>start:{{startNum}}</view>
		<view>end:{{endNum}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				KeyboardHeight: 0,
				startNum: 0,
				endNum: 0
			}
		},
		onLoad() {
			this.KeyboardHeightChange()
		},
		methods: {
			keyBoard1() {
				uni.hideKeyboard()
			},
			KeyboardHeightChange() {
				uni.onKeyboardHeightChange(res => {
					console.log(res.height)
				})
			},
			keyBoard2() {
				uni.offKeyboardHeightChange()
			},
			focus() {
				let _this = this;
				uni.getSelectedTextRange({
					success: res => {
						console.log('getSelectedTextRange res', res.start, res.end)
						_this.startNum = res.start
						_this.endNum = res.end
					}
				})
			}
		}
	}
</script>

<style scoped>

</style>
